package com.bw.lib_widget.test

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup

/**
 * @author ytx
 * @date 2025-09-22 14:09
 * @description
 */
class MyViewGroup:ViewGroup {
    constructor(context: Context?):super(context){
    }
    constructor(context: Context?, attrs: AttributeSet?):super(context,attrs){

    }
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int):super(context,attrs,defStyleAttr){

    }

    /**
     * 必须测量子控件大小，不然onLayout无法获得子控件宽度和高度
     */
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        measureChildren(widthMeasureSpec,heightMeasureSpec) //测量子View的大小
        //测量自己的大小
    }

    /**
     * 必须重写还得设置子控件的位置
     */
    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        val child = getChildAt(0)
        child.layout(0,0,child.measuredWidth,child.measuredHeight)

    }
}